package com.chuangke.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.system.entity.SysAphorism;
import com.chuangke.system.service.SysAphorismService;

@RestController
@RequestMapping("aphorism")
public class SysAphorismController {

	@Autowired
	private SysAphorismService sysAphorismService;

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody SysAphorism sysAphorism) {
		sysAphorismService.save(sysAphorism);
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/delete")
	public HttpResult shiftDelete(@RequestBody List<String> ids) {
		ids.forEach(id -> sysAphorismService.delete(id));
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/randomfind")
	public HttpResult find() {
		return HttpResult.ok(sysAphorismService.findRandom());
	}

}
